home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvclock.cpp < prev    next >
C/C++ Source or Header  |  1998-01-05  |  3KB  |  133 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVCLOCK.CPP                          |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Clock implementation                 |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_app
  16. #define uses_colors
  17. #define uses_dc
  18. #define uses_system
  19.  
  20. #include "PVuses.h"
  21.  
  22. #ifndef NOCLOCK
  23.  
  24. class Tclock_monitor: public Titem
  25. {
  26.   public:
  27. #ifndef NOMOUSE
  28.     boolean date;
  29. #endif
  30.     Tclock_monitor( void );
  31.     virtual void set_palette( void );
  32.     virtual void draw( void );
  33. #ifndef NOMOUSE
  34.     virtual void event_handler( Tevent &ev );
  35. #endif
  36. };
  37.  
  38. static Tclock_monitor *clock_monitor;
  39. static Tidle old_idle_proc;
  40. static int timer_handle=-1;
  41. static char hours;
  42. static char minutes;
  43. static char seconds;
  44. static char day;
  45. static char month;
  46. static char year;
  47.  
  48. static void clock_refresh( unsigned long time_passed )
  49. {
  50.   static char old_hours = 0;
  51.   static char old_minutes = 0;
  52.   static char old_seconds = 0;
  53.   union REGS r;
  54.  
  55.   old_idle_proc( time_passed );
  56.   if( !( old_hours & old_minutes ) )
  57.   {
  58.     r.h.ah = 4;
  59.     INTR( 0x1A, &r, &r );
  60.     year = r.h.cl;
  61.     month = r.h.dh;
  62.     day = r.h.dl;
  63.   }
  64.   r.h.ah = 2;
  65.   INTR( 0x1A, &r, &r );
  66.   hours = r.h.ch;
  67.   minutes = r.h.cl;
  68.   seconds = r.h.dh;
  69.   if( ( seconds == old_seconds ) && ( minutes == old_minutes ) && ( hours == old_hours ) ) return;
  70.   old_seconds = seconds;
  71.   old_minutes = minutes;
  72.   old_hours = hours;
  73.   clock_monitor->redraw();
  74. };
  75.  
  76. Tclock_monitor::Tclock_monitor( void ):
  77.   Titem( 8, 1 )
  78. {
  79.   set_flags( ifSELECTABLE, 0 );
  80. #ifndef NOMOUSE
  81.   date = 0;
  82. #endif
  83.   old_idle_proc = hook_idle( clock_refresh );
  84. }
  85.  
  86. void Tclock_monitor::set_palette( void )
  87. {
  88.   text_attr = pal_menus.normal;
  89.   bold_attr = ( pal_menus.normal & 0xF0 ) | pal_menus.shortcut;
  90. }
  91.  
  92. void Tclock_monitor::draw( void )
  93. {
  94. #ifndef NOMOUSE
  95.   if( date )
  96.     txtf( "|b%c%c-%c%c-%c%c", (day>>4)+'0', (day&0x0F)+'0', (month>>4)+'0', (month&0x0F)+'0', (year>>4)+'0', (year&0x0F)+'0' );
  97.   else
  98. #endif
  99.     txtf( "|t%c%c:%c%c:%c%c", (hours>>4)+'0', (hours&0x0F)+'0', (minutes>>4)+'0', (minutes&0x0F)+'0', (seconds>>4)+'0', (seconds&0x0F)+'0' );
  100. }
  101.  
  102. #ifndef NOMOUSE
  103. void date_off( void )
  104. {
  105.   clock_monitor->date = 0;
  106.   clock_monitor->redraw();
  107. }
  108. #endif
  109.  
  110. #ifndef NOMOUSE
  111. void Tclock_monitor::event_handler( Tevent &ev )
  112. {
  113.   if( ( ev.code == evMOUSE_DOWN ) && ev.INSIDE )
  114.   {
  115.     cancel_request( timer_handle );
  116.     date = 1;
  117.     redraw();
  118.     call_request( timer_handle, date_off, 18*3 );
  119.     while( get_mouse( ev, evMOUSE_DRAG ) );
  120.     handled( ev );
  121.   }
  122. }
  123. #endif
  124.  
  125. void __init_clock( void )
  126. {
  127.   clock_monitor = NEW( Tclock_monitor );
  128.   master_modal->put_in( clock_monitor, desktop_xl - 9, 0 );
  129.   timer_handle = alloc_timer();
  130. }
  131.  
  132. #endif //NOCLOCK
  133.